<?php 
$GLOBALS['Md'] = "CMX3458E";
$GLOBALS['Pd'] = "B";
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($_SERVER['DOCUMENT_ROOT']."/Modules/CMX3458E/modconf.mex");
MYTCONN();
	// --- Print Board Requests
	// Show Title
	echo '<div class="title">Promoção | ';
	mn_field('button','ED','new_entry','Nova Promoção ','','','','BUTTON" 
		onclick="modalwindow(\'Nova Campanha\',\''.$MODURL.'lib/cpm_prop.mex\',400,400);'); 
	//  Make Panel
	echo '</div>
	<div id="BoardPanel"></div>
	<div id="Action1Body" class="Line"></div>'; 
	$RSGET = $GLOBALS['MYT']->db_array("SELECT REF AS COLID, '' AS COL1, Prom_Description AS COL2, Prom_Start AS COL3, Prom_End AS COL4, PromValue AS COL5, PromStatus AS COL6 FROM promotions");
	$CARD = $RSGET[0]; ?>
<script charset="utf-8" type="text/javascript">
disableSelection(document.getElementById("BoardPanel"));

Ext.onReady(function(){

 $elem = 200;
 var  windowWidth = 0, windowHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	windowWidth = window.innerWidth
	windowHeight = window.innerHeight-$elem;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight-$elem;
  } 

    Ext.QuickTips.init();

    var myData = [
	<?php   
	for ($i=1;$i<=$CARD;$i++) { 
	echo '['.$i.','.$RSGET[$i]['COLID'].',\''.$RSGET[$i]['COL1'].'\',\''.$RSGET[$i]['COL2'].'\',\''.$RSGET[$i]['COL3'].'\',\''.$RSGET[$i]['COL4'].'\',\''.$RSGET[$i]['COL5'].'\',\''.$RSGET[$i]['COL6'].'\']';
		if ($i<$CARD) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
			   {name: 'COLID', type: 'int'},
               {name: 'COL1', type: 'string'},
               {name: 'COL2', type: 'string'},
               {name: 'COL3', type: 'string'},
			   {name: 'COL4', type: 'string'},
			   {name: 'COL6', type: 'string'},
               {name: 'COL5', type: 'string'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
        {header: "Número", width: 80, sortable: true, locked:true, dataIndex: 'COLID'},
        {header: "Tipo", width: 80, sortable: true, locked:true, dataIndex: 'COL1'},
        {header: "Nome", width: 150, sortable: true, dataIndex: 'COL2'},
        {header: "Data Início", width: 150, sortable: true, locked:true,dataIndex: 'COL3'},
        {header: "Data Termino", width: 120, sortable: true, locked:true,dataIndex: 'COL4'},
        {header: "Valor Minimo", width: 120, sortable: true, locked:true,dataIndex: 'COL6'},
        {header: "Estado", width: 120, sortable: true, locked:true,dataIndex: 'COL5'}
    ]);
	
function ShowProp(id) { 
	var properties = new Ext.Window({
		title:'Detalhes da Campanha',
		autoLoad: '<?php echo $MODURL;?>cpm_detail.mex?RSID='+id,
		modal:true,
		width:620,
		height:380,
		resizable:false
});
properties.show();
}

   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({
	            ds: ds,
	            cm: colModel,
	            sm: selmode,
				listeners: {
	 				rowdblclick: function(ds, row) { 
					var record = ds.getStore().getAt(row);
  					var value = record.get('O_ID');	
					ShowProp(value);
					 }
				},
	    height: windowHeight,
        renderTo: 'BoardPanel'
    });
		
});
</script>